home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_005 / singleplayfield / singleplayfield.c < prev   
C/C++ Source or Header  |  1992-05-06  |  6KB  |  201 lines

  1. /*
  2.  *
  3.  *    DISCLAIMER:
  4.  *
  5.  *    This program is provided as a service to the programmer
  6.  *    community to demonstrate one or more features of the Amiga
  7.  *    personal computer.  These code samples may be freely used
  8.  *    for commercial or noncommercial purposes.
  9.  * 
  10.  *     Commodore Electronics, Ltd ("Commodore") makes no
  11.  *    warranties, either expressed or implied, with respect
  12.  *    to the program described herein, its quality, performance,
  13.  *    merchantability, or fitness for any particular purpose.
  14.  *    This program is provided "as is" and the entire risk
  15.  *    as to its quality and performance is with the user.
  16.  *    Should the program prove defective following its
  17.  *    purchase, the user (and not the creator of the program,
  18.  *    Commodore, their distributors or their retailers)
  19.  *    assumes the entire cost of all necessary damages.  In 
  20.  *    no event will Commodore be liable for direct, indirect,
  21.  *    incidental or consequential damages resulting from any
  22.  *    defect in the program even if it has been advised of the 
  23.  *    possibility of such damages.  Some laws do not allow
  24.  *    the exclusion or limitation of implied warranties or
  25.  *    liabilities for incidental or consequential damages,
  26.  *    so the above limitation or exclusion may not apply.
  27.  *
  28.  */
  29.  
  30. /* singlePlayfield.c */
  31.  
  32.  
  33. /* This program creates and displays a 320 by 200 by 2 bit plane
  34.  * single playfield display.  
  35.  */
  36.  
  37. /* author:  Rob Peck, 12/1/85 */
  38.  
  39. /* This code may be freely utilized to develop programs for the Amiga. */
  40.  
  41.  
  42.  
  43. #include "exec/types.h"
  44. #include "graphics/gfx.h"
  45. #include "hardware/dmabits.h"
  46. #include "hardware/custom.h"
  47. #include "hardware/blit.h"
  48. #include "graphics/gfxmacros.h"
  49. #include "graphics/copper.h"
  50. #include "graphics/view.h"
  51. #include "graphics/gels.h"
  52. #include "graphics/regions.h"
  53. #include "graphics/clip.h"
  54. #include "exec/exec.h"
  55. #include "graphics/text.h"
  56. #include "graphics/gfxbase.h"
  57.  
  58.  
  59. #define DEPTH 2  
  60. #define WIDTH 320 
  61. #define HEIGHT 200 
  62. #define NOT_ENOUGH_MEMORY -1000
  63. /* construct a simple display */ 
  64.  
  65. struct View v;
  66. struct ViewPort vp;
  67. struct ColorMap *cm;    /* pointer to colormap structure, dynamic alloc */
  68. struct RasInfo ri;
  69. struct BitMap b;    /* note:  Due to the static allocation of a
  70.              * structure accessed directly by the custom
  71.              * chips, this program will only work if it
  72.              * resides entirely within the lower 512k
  73.              * bytes of memory (CHIP memory)
  74.              */
  75. struct RastPort rp;
  76.  
  77. LONG i;
  78. SHORT j,k,n;
  79.  
  80. extern struct ColorMap *GetColorMap();
  81. struct GfxBase *GfxBase;
  82.  
  83. struct View *oldview;        /* save pointer to old view so can restore */
  84.  
  85. USHORT colortable[] = { 0x000, 0xf00, 0x0f0, 0x00f }; /* my own colors */
  86.                         /* black, red, green, blue */
  87. SHORT  boxoffsets[] = { 802, 2010, 3218 };    /* where to draw boxes */
  88.  
  89. UBYTE *displaymem;
  90. UWORD *colorpalette;
  91.  
  92. main()
  93. {
  94.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  95.     if (GfxBase == NULL) exit(1);
  96.     oldview = GfxBase->ActiView; /* save current view to restore later */
  97.     /* example steals screen from Intuition if started from WBench */
  98.  
  99.     InitView(&v);        /* initialize view */
  100.     InitVPort(&vp);     /* init view port */
  101.     v.ViewPort = &vp;     /* link view into viewport */
  102.  
  103.     /* init bit map (for rasinfo and rastport) */
  104.     InitBitMap(&b,DEPTH,WIDTH,HEIGHT);
  105.  
  106.     /* (init RasInfo) */
  107.     ri.BitMap = &b;
  108.     ri.RxOffset = 0;    
  109.     ri.RyOffset = 0;
  110.     ri.Next = NULL;
  111.  
  112.     /* now specify critical characteristics */
  113.     vp.DWidth = WIDTH;
  114.     vp.DHeight = HEIGHT;
  115.     vp.RasInfo = &ri;
  116.  
  117.     /* (init color table) */
  118.     cm = GetColorMap(4);    /* 4 entries, since only 2 planes deep */
  119.     colorpalette = (UWORD *)cm->ColorTable;
  120.     for(i=0; i<4; i++)
  121.         *colorpalette++ = colortable[i];
  122.  
  123.     /* copy my colors into this data structure */
  124.     vp.ColorMap = cm;    /* link it with the viewport */
  125.  
  126.     /* allocate space for bitmap */
  127.     for(i=0; i<DEPTH; i++)
  128.     {
  129.         b.Planes[i] = (PLANEPTR)AllocRaster(WIDTH,HEIGHT);
  130.         if(b.Planes[i] == NULL) exit(NOT_ENOUGH_MEMORY);
  131.     }
  132.  
  133.     MakeVPort( &v, &vp );    /* construct copper instr (prelim) list */
  134.     MrgCop( &v );        /* merge prelim lists together into a real 
  135.                  * copper list in the view structure. */
  136.  
  137.         for(i=0; i<2; i++)
  138.         {
  139.                 displaymem = (UBYTE *)b.Planes[i];
  140.                 for(j=0; j<RASSIZE(WIDTH,HEIGHT); j++) {
  141.                         *displaymem++ = 0;
  142.                 }
  143.                 /* zeros to all bytes of the display area */
  144.         }
  145.  
  146.     LoadView(&v);
  147.         /* now fill some boxes so that user can see something */
  148.         /* always draw into both planes to assure true colors */
  149.         for(n=1; n<4; n++)      /* three boxes */
  150.         {
  151.                 for(k=0; k<2; k++)
  152.                 {
  153.                         /* boxes will be in red, green and blue */
  154.                         displaymem = b.Planes[k] + boxoffsets[n-1];
  155.                         DrawFilledBox(n,k);
  156.                 }
  157.         }
  158.  
  159.     for(i=0; i<100000;i++) ;    /* do nothing for a while */
  160.  
  161.     LoadView(oldview);        /* put back the old view  */
  162.  
  163.     FreeMemory();            /* exit gracefully */
  164.     CloseLibrary(GfxBase);    /* since opened library, close it */
  165.  
  166. }    /* end of main() */
  167.  
  168. /* return user and system-allocated memory to sys manager */
  169. FreeMemory()
  170. {
  171.     /* free drawing area */
  172.     for(i=0; i<DEPTH; i++) 
  173.         FreeRaster(b.Planes[i],WIDTH,HEIGHT); 
  174.     /* free the color map created by GetColorMap() */
  175.     FreeColorMap(cm);
  176.     /* free dynamically created structures */
  177.     FreeVPortCopLists(&vp);            
  178.     FreeCprList(v.LOFCprList);
  179.     return(0);
  180. }    
  181. DrawFilledBox(fillcolor,plane)
  182. SHORT fillcolor,plane;
  183. {
  184.         UBYTE value;
  185.         for(j=0; j<100; j++)
  186.         {
  187.                 if((fillcolor & (1 << plane)) != 0)
  188.                         value = 0xff;
  189.                 else
  190.                         value = 0;
  191.                 for(i=0; i<20; i++)
  192.                 {
  193.                         *displaymem++ = value;
  194.                 }
  195.                 displaymem += (b.BytesPerRow - 20);
  196.         }
  197.         return(0);
  198. }
  199.  
  200.  
  201.